<?php
getHeader();

?>
<div id="content">
<div class="tabs headTabs">
<ul>
	<li><a href='?p=uploadImage&action=createAlbum' class="TabLink">创建相册</a>
	<a href='?p=uploadImage' class="TabLink">上传图片</a></li>
</ul>
<span>图片上传</span></div>
<div class="dataList"><?php
if (isset($_FILES['uploadImage']))
{
	if (!isset($_SESSION['authPassed']) || $_SESSION['authPassed'] != "TRUE")
	{
		echo "<span>你未登录, 不能上传图片</span>";
	}
	else
	{
		$person = userProf::getUserByUid((int)$_SESSION['uid']);
		switch ($person->imageUpload($_FILES['uploadImage'],$_POST['imageAlbum']))
		{
			case 0:
				echo "<span>上传成功.</span>";
				break;
					
			case 1:
				echo "<span>文件类型或大小不符合要求, 上传失败.</span>";
				break;

			case 2:
				echo "<span>该文件名已存在, 请修改同名文件后再上传.</span>";
				break;
			default:
				echo "";
		}
		echo "&nbsp;&nbsp;&nbsp;&nbsp;<a href='?p=uploadImage'>继续上传</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href='?p=viewUser'>返回</a>";
	}
}
else if (isset($_POST['albumName']))
{
	if (!isset($_SESSION['authPassed']) || $_SESSION['authPassed'] != "TRUE")
	{
		echo "<span>你未登录, 不能创建相册</span>";
	}
	$person = userProf::getUserByUid((int)$_SESSION['uid']);
	if ($person->albumCreate($_POST['albumName']))
	{
		echo "<span>创建成功.</span>";
	}
	else
	{
		echo "<span>创建失败.</span>";
	}
}
else
{
	if (!isset($_SESSION['authPassed']))
	{
		echo "<span>你未登录, 不能上传图片</span>";
	}
	else if (!isset($_GET['action']))
	{
		$person = userProf::getUserByUid((int)$_SESSION['uid']);
		$album = $person->getUserAlbum();
		if ($album == "NO")
		{
			echo "<span>你还没有相册目录, 请至少<a href='?p=uploadImage&action=createAlbum'>创建</a>一个相册后再上传相片.";
		}
		else
		{
			?>
<form action='?p=uploadImage' method='post'
	enctype="multipart/form-data"><span>图片: </span><input type="file"
	name="uploadImage" /><br />
<span>所属相册: </span> <select name="imageAlbum">
<?php
while ($arr = mysql_fetch_array($album))
{
	echo "<option value='{$arr['aid']}'>{$arr['albumName']}</option>";
}
?>
</select> <input type="submit" name="submit" value="上传" class="button" />
</form>
<?php
		}
	}
	else if ($_GET['action'] == 'createAlbum')
	{
		?>
<form action='?p=uploadImage' method='post'><span>相册名: </span><input
	type="text" name="albumName" /><br />
<input type="submit" name="submit" value="创建" class="button" /></form>
		<?php
	}
}
?></div>
</div>
<?php
getPanel();
getFooter();
?>
